package org.jeecg.modules.sistersophie.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.sistersophie.entity.AccountInfo;
import org.jeecg.modules.sistersophie.mapper.AccountInfoMapper;
import org.jeecg.modules.sistersophie.service.IAccountInfoService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.transaction.Transactional;
import java.math.BigDecimal;

/**
 * @Description: account_info
 * @Author: jeecg-boot
 * @Date:   2021-05-30
 * @Version: V1.0
 */
@Service
public class AccountInfoServiceImpl extends ServiceImpl<AccountInfoMapper, AccountInfo> implements IAccountInfoService {


    public AccountInfo selectByStudentId(Integer studentId,Integer accountType){
        QueryWrapper<AccountInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("student_id",studentId).eq("account_type",accountType).eq("is_delete",0);
        return this.baseMapper.selectOne(queryWrapper);
    }
    /**
     * 账户添加金额
     * @param id
     * @param amount
     * @param version
     */
    @Transactional
    public int addAccount(Integer id, BigDecimal amount,Integer version){
        return  this.baseMapper.addAccount(id,amount,version);
    }

    /**
     * 账户添加金额
     * @param id
     * @param amount
     * @param version
     */
    @Transactional
    public int subAccount(Integer id, BigDecimal amount,Integer version){
        return  this.baseMapper.subAccount(id,amount,version);
    }

    @Transactional
    public int freeAccount(Integer id, BigDecimal amount,Integer version){
        return  this.baseMapper.freeAccount(id,amount,version);
    }

    @Transactional
    public int unFreeAccount(Integer id, BigDecimal amount,Integer version){
        return  this.baseMapper.unFreeAccount(id,amount,version);
    }

}
